package org.eiahe.hr.performance.controller;

import lombok.RequiredArgsConstructor;
import org.ehe.common.core.BaseController;
import org.eiahe.hr.performance.domain.PerformanceScorer;
import org.eiahe.hr.performance.domain.bo.PerformanceScorerBo;
import org.eiahe.hr.performance.domain.vo.PerformanceScorerVo;
import org.eiahe.hr.performance.service.IPerformanceScorerService;
import org.ehe.common.core.domain.R;
import org.ehe.common.log.annotation.Log;
import org.ehe.common.log.enums.BusinessType;
import org.ehe.common.mybatis.core.page.PageQuery;
import org.ehe.common.mybatis.core.page.TableDataInfo;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import cn.dev33.satoken.annotation.SaCheckPermission;

import java.util.List;

/**
 * 评分人设置Controller
 *
 * @author zhangnn
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/performance/scorer")
public class PerformanceScorerController extends BaseController {

    private final IPerformanceScorerService performanceScorerService;

    /**
     * 查询评分人设置列表
     */
    @SaCheckPermission("performance:scorer:list")
    @GetMapping("/list")
    public TableDataInfo<PerformanceScorerVo> list(PerformanceScorerBo scorer, PageQuery pageQuery) {
        return performanceScorerService.queryPageListVo(scorer, pageQuery);
    }

    /**
     * 获取评分人设置详细信息
     */
    @SaCheckPermission("performance:scorer:query")
    @GetMapping(value = "/{id}")
    public R<PerformanceScorerVo> getInfo(@PathVariable("id") Long id) {
        return R.ok(performanceScorerService.queryById(id));
    }

    /**
     * 新增评分人设置
     */
    @SaCheckPermission("performance:scorer:add")
    @Log(title = "评分人设置", businessType = BusinessType.INSERT)
    @PostMapping
    public R<Void> add(@Validated @RequestBody PerformanceScorerBo scorer) {
        return toAjax(performanceScorerService.insertByBo(scorer));
    }

    /**
     * 修改评分人设置
     */
    @SaCheckPermission("performance:scorer:edit")
    @Log(title = "评分人设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<Void> edit(@Validated @RequestBody PerformanceScorerBo scorer) {
        return toAjax(performanceScorerService.updateByBo(scorer));
    }

    /**
     * 删除评分人设置
     */
    @SaCheckPermission("performance:scorer:remove")
    @Log(title = "评分人设置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@PathVariable Long[] ids) {
        return toAjax(performanceScorerService.deleteWithValidByIds(List.of(ids), true));
    }
}